home *** CD-ROM | disk | FTP | other *** search
- Path: news.infi.net!usenet
- From: nngis@norfolk.infi.net (Greg DiGiorgio)
- Newsgroups: comp.lang.c
- Subject: Re: Checking for a file => Does it exist (Help)
- Date: 16 Jan 1996 02:27:31 GMT
- Organization: Customer of InfiNet
- Message-ID: <4df2ej$pqr@news.infi.net>
- References: <4d9k6fINNnja@faatcrl.faa.gov>
- NNTP-Posting-Host: h-hanuman.norfolk.infi.net
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- In article <4d9k6fINNnja@faatcrl.faa.gov>, afrawert@faatcrl.faa.gov
- says...
- >
- >
- >
- > I'm having a problem just checking to see if a
- file
- >exists. Does anyone have a simple piece of code that I can use?
- >
- > afrawert@faatcrl.faa.gov
- >
- >
- A simple way is to try and open the file. If it opens successfully, then
- it exists. If not, then either it does not exist or you don't have rad
- permission (UNIX).
-
- #include <stdio.h>
- #define NOTEXIST 0
- #define EXIST 1
- int file_exist(char filespec[]) {
- FILE *f;
- f=fopen(filespec,"rt");
- if (!f) return(NOTEXIST);
- fclose(f);
- return(EXIST);
- }
-
- Of course, there is some overhead associated with open/close a file.
-
- Hope this helps,
- Greg DiGiorgio
-
-